{{extends file = "../layout.html"}}

{{block name = title}}{{$it.title}} - {{$smarty.block.parent}}{{/block}}

{{block name = head}}
{{$smarty.block.parent}}
<link rel="stylesheet" href="{{__STATIC__}}/css/common.css"/>
{{/block}}

{{block name = location}}
<ul class="breadcrumb">
    <li>
        <i class="icon-home home-icon"></i>
        <a href="/">首页</a>
    </li>
    <li>
        <i class="icon-home home-icon"></i>
        <a href="#">文章</a>
    </li>
    <li>
        <i class="icon-home home-icon"></i>
        <a href="#">{{$it.title}}</a>
    </li>
</ul><!-- .breadcrumb -->
{{/block}}

{{block name = content}}

<div class="post-wrap">
    <div class="page-header">
        <h1>{{$it.title}}</h1>
    </div>

    <div class="content">
        <p class="post-meta">作者：<a href="/account/{{$it.author}}">{{$it.author}}</a> | 时间：{{$it.publish_time}} |
            评论：{{$it.comment_num}} | 点击：{{$it.views}} | 分类：{{$it.category}} {{if $u_type eq 'admin'}}| <a
                    href="/admin?p=post&a=modify&id={{$it.id}}">编辑</a>{{/if}}</p>

        <p class="summary">{{$it.summary}}</p>

        <div class="content-inner">
            {{$it.content}}
        </div>


    </div>
    <div class="comment-wrap">
        <form action="/comment/post?id={{$it.id}}" method="post" id="frm-com">
            <div>
                <label for="tta"><h3>评论</h3></label>

                <textarea class="form-control" id="tta" placeholder="请输入评论" name="comment[content]"></textarea>
            </div>
            <br>
            <input type="hidden" name="backurl" value="" id="backurl">
            <button class="btn-comment btn-info" type="button">
                <i class="icon-ok bigger-110"></i>
                发表评论
            </button>
        </form>


        <div class="comment-list">
            <ol> {{if $comment eq true}}
                {{foreach from = $comment item = cm}}
                <li class="text-primary">
                    {{$cm.author}} - {{$cm.publish_time}} <br/>
                    {{$cm.content}}
                </li>
                {{/foreach}}
                {{/if}}
            </ol>
        </div>

    </div>
</div>

{{/block}}

{{block name =foot}}
{{$smarty.block.parent}}

<script>
    $(function () {
        $(".btn-comment").click(function () {
            //data应该是一个对象
            var _data = {};
            _data.attach         = "{{$it.id}}";
            _data.attach         = parseInt(_data.attach);
            _data.content    = $("#tta").val();
            $.ajax({
                type    : 'post',
                url     : "/post/addComment",
                data    : {data : _data},
                //dataType: 'JSON',
                success : function(data){
                     data = $.parseJSON(data);
                    if(data.status == true){
                        alert("发布成功!");
                        $("#tta").val('');
                        $(".comment-list ol").append(' <li class="text-primary">' + data.author + ' - ' + data.publish_time + ' <br/>' + data.content + '</li>')
                    }else{
                        alert('发布失败，请重试!');
                    }
                },
                error   : function(data){
                    alert(data.toString);
                    alert('出现错误');
                }

            })















        })
    })

</script>
{{/block}}